//dfs 暴力搜索
class Solution {
public:
    vector<bool> vis;
    vector<vector<int>> g;
    vector<vector<int>> ans;

    void dfs(int cur,int idx)
    {
        vis[cur] = true;
        for(auto& next : g[cur])
        {
            if(vis[next]) continue;
            ans[next].push_back(idx);
            dfs(next,idx);
        }
    }

    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {
        vis.resize(n);    
        g.resize(n);
        ans.resize(n);

        for(auto& e : edges)
        {
            g[e[0]].push_back(e[1]);
        }

        for(int i = 0;i < n;i++)
        {
            fill(vis.begin(),vis.end(),false);
            dfs(i,i);
        }
        return ans;
    }
};